package com.ruoyi.project.remoteControl.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.project.remoteControl.domain.DeviceAliveInfo;
import com.ruoyi.project.remoteControl.service.ReceiveAliveMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 主控端负责接收和处理远程被控端状态信息的Controller
 */
@RestController
@Slf4j
public class ReceiveAliveMsgController {
    @Autowired
    ReceiveAliveMsgService receiveAliveMsgService;

    /**
     * 处理远控端发送来的存活信息
     * @param deviceAliveInfo
     * @return
     */
    @Anonymous //设置该接口在系统外可以直接调用而不需要登录或者token认证
    @PostMapping("/isAlive")
    public String isAlive(@RequestBody DeviceAliveInfo deviceAliveInfo){
        log.info("接收到" + deviceAliveInfo.getDeviceName() + "的状态信息：" + deviceAliveInfo);
        // 数据库中没有则插入，否则进行更新
        receiveAliveMsgService.insertOrUpdateRemoteComputerStatus(deviceAliveInfo);
        return "状态信息发送成功！";
    }
}
